package com.hjwoo.app.views;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;

import com.google.gson.Gson;
import com.hjwoo.app.R;
import com.hjwoo.app.baseviews.BaseAppCompatActivity;
import com.hjwoo.app.been.RegisterResult;
import com.hjwoo.app.been.UserAccessTokenOBJ;
import com.hjwoo.app.common.AppManager;
import com.hjwoo.app.common.LoanApplication;
import com.hjwoo.app.fragment.UserCenterFragment;
import com.hjwoo.app.utils.LoanAccessTokenIdKeeper;
import com.hjwoo.app.utils.LoanToast;
import com.hjwoo.app.utils.Utils;

/**
 * Created by yangchuan on 2016/5/23.
 */
public class ResetSuccessActivity extends BaseAppCompatActivity
{

    String result;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_resetsuccess);
        Utils.initTitle("找回密码", ResetSuccessActivity.this, true);

        if (getIntent() != null)
        {
            result = getIntent().getStringExtra("result");
        }


        findViewById(R.id.resetsuccess_login_btn).setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                Gson           gson = new Gson();
                RegisterResult rr   = gson.fromJson(result, RegisterResult.class);

                LoanToast.showToastShort("登录成功", ResetSuccessActivity.this);

                UserAccessTokenOBJ userAccessTokenOBJ = new UserAccessTokenOBJ();
                userAccessTokenOBJ.setAppSessionId(rr.getAppSessionId());
                //将id保存
                LoanAccessTokenIdKeeper.writeAccessToken(ResetSuccessActivity.this, userAccessTokenOBJ);

                Message message = new Message();
                message.what = UserCenterFragment.USER_ISLOGIN;
                //获取用户handler
                UserCenterFragment.MyUserCenterHandler myUserCenterHandler = (UserCenterFragment.MyUserCenterHandler) LoanApplication.getInstance().getHandler();
                myUserCenterHandler.sendMessage(message);
                AppManager.getAppManager().finishAllActivity();

            }
        });
        findViewById(R.id.resetsuccess_go_btn).setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View view)
            {
                //回首页
                MainActivity.currIndex = 0;
                MainActivity.showFragment();
                MainActivity.group.check(R.id.foot_bar_home);
                AppManager.getAppManager().finishAllActivity();
            }
        });
    }

    private class TestThread extends Thread
    {
        private Handler mmHandler;

        public TestThread(Handler handler)
        {
            mmHandler = handler;
        }

        public void run()
        {
            mmHandler.sendEmptyMessage(UserCenterFragment.USER_ISLOGIN);
        }
    }

}
 
